Ext.namespace("GridBsRepeater");

GridBsRepeater.Detail = function(plist){
	
	this.parentList = plist;
	
	//网络资源编号
	this.txtNrId = new Ext.form.Hidden({
		name:'nrId'
	});
	//直放站名称
	this.txtNrName = new Ext.form.TextField({
		fieldLabel : '直放站名称',
		name :'nrName',
		width : 200,
		allowBlank : false,
        blankText : '请输入直放站名称!'
	});
	
	//网络资源类型
	this.txtNrType = new Ext.form.Hidden({
		name: 'nrType',
		value: '2'
	});
	
	//站址
	this.txtNrAddress = new Ext.form.Hidden({
		name : 'nrAddress'
	});
	//路
	this.txtAddressInfoStreet = new Ext.form.TextField({
		fieldLabel : '站址 路',
		name :'addressInfo.street',
		width : 150
	});
	//弄
	this.txtAddressInfoAlley = new Ext.form.NumberField({
		fieldLabel: '弄',
		name :'addressInfo.alley',
		width: 60
	});
	//号
	this.txtAddressInfoDoorNum = new Ext.form.NumberField({
		fieldLabel: '号',
		name :'addressInfo.doorNum',
		width: 60
	});
	//楼名
	this.txtAddressInfoBuildingName = new Ext.form.TextField({
		fieldLabel : '楼宇名称',
		name :'addressInfo.buildingName',
		width : 150
	});
	//楼层
	this.txtAddressInfoFloor = new Ext.form.NumberField({
		fieldLabel: '楼层',
		name :'addressInfo.floor',
		width: 60
	});
	
	//直放站位置描述
	this.txtLocationDesc = new Ext.form.TextArea({
		fieldLabel : '直放站位置描述',
		name :'locationDesc',
		width : 400
	});
	
	//直放站编号
	this.txtrptId = new Ext.form.Hidden({
		name:'rptId'
	});
	
	
	//设备具体位置
	this.txtEquipmentPosition = new Ext.form.TextArea({
		fieldLabel : '设备具体位置',
		name :'equipmentPosition',
		width : 400
	});
	
	//覆盖面积（万平方米）
	this.txtareaSize = new Ext.form.NumberField({
		fieldLabel: '覆盖面积（万平方米）',
		name :'areaSize',
		width: 120
	});
    
	//直放站类型
	this.cmbRptType = new Ext.form.ComboBox({
		width : 120,
        fieldLabel : '直放站类型',
        store: [],//OMS.NETWORK_RESOURCE_TYPE,
        typeAhead:true,
        name : 'rptType',
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true	
	});
	
	//设备型号
	this.txtEquipmentType = new Ext.form.NumberField({
		fieldLabel: '设备型号',
		name :'equipmentType',
		width: 120
	});
	
	//监控卡号
	this.txtMonitoringCardId = new Ext.form.NumberField({
		fieldLabel: '监控卡号',
		name :'monitoringCardId',
		width: 120
	});
	
	//入网年月
    this.dfEnterNetDate = new Ext.form.DateField({
    	fieldLabel :'入网年月:',
    	name : 'enterNetDate',
    	labelSeparator: '',
		width: 120,
		format: 'Y-m-d'
	});
	
	//区域
	this.txtAreaRange = new Ext.form.TextArea({
		fieldLabel : '区域',
		name :'areaRange',
		width : 400
	});
	
	//设备厂商
	this.txtEquipmentManufacturer = new Ext.form.TextField({
		fieldLabel : '设备厂商',
		name :'equipmentManufacturer',
		width : 150
	});
	
	//基本信息
	this.basicForm = new Ext.form.FormPanel({
		bodyStyle : 'padding: 5px 5px 0',
		frame :true,
		autoScroll : true,
		height: 390,
		width : 700,
		labelAlign: 'right',
		labelWidth : 150,
		layout : 'table',
		layoutConfig : {columns:2},
		items:[
			{colspan:2,layout:'form',items:[this.txtNrName]},
			{colspan:2,layout:'form',items:[this.txtAddressInfoStreet]},
			{colspan:2,layout:'form',items:[this.txtAddressInfoAlley]},
			{colspan:2,layout:'form',items:[this.txtAddressInfoDoorNum]},
			{colspan:2,layout:'form',items:[this.txtAddressInfoBuildingName]},
			{colspan:2,layout:'form',items:[this.txtAddressInfoFloor]},	
			{colspan:2,layout:'form', items:[this.txtLocationDesc]},
            //{layout:'form', items:[this.cmbbsId]},
            {colspan:2,layout:'form', items:[this.txtareaSize]},       
            {colspan:2,layout:'form',items:[this.txtEquipmentPosition]},  
            {layout:'form', items:[this.cmbRptType]},
            {layout:'form', items:[this.txtEquipmentType]}, 
            {layout:'form', items:[this.txtMonitoringCardId]},
            {layout:'form', items:[this.dfEnterNetDate]},     
            {colspan:2,layout:'form',items:[this.txtAreaRange]},
            {colspan:2,layout:'form',items:[this.txtEquipmentManufacturer]},
            {layout:'form', items:[this.txtNrId]},
            {layout:'form', items:[this.txtNrType]},
            {layout:'form', items:[this.txtNrAddress]},
            {layout:'form', items:[this.txtrptId]}
		]
	});
	
	//GIS信息
	//片区属地
	this.txtGisId = new Ext.form.Hidden({
		name: 'gisInfo.id'
	});
	
	this.txtGisType = new Ext.form.Hidden({
		name: 'gisInfo.type',
		value: 2
	});	
	
	this.cmbDistrictList = new Ext.form.ComboBox({
        width: 130,
        listWidth:150,
        id : 'cmbDistrictList',
        fieldLabel: '片区属地',
        name : 'gridId',
        store : new Ext.data.JsonStore({
		   url:"../gridareas/listAllDistricts.form",
		   autoLoad : true,
		   root:"districts",
		   fields:["areaId","name"]
		}),
		valueField : 'areaId',
		displayField :'name',
        mode: 'local',
        //typeAhead:true,
        emptyText:'',
        triggerAction: 'all',
        selectOnFocus: true
    });

	 this.bsIdStore= new Ext.data.JsonStore({
		   url:"../gridnetworkresource/listAllBaseStation.form",
		   //autoLoad : true,
		   root:"listBsStation",
		   fields:["nrId","nrName"]
	});
    
    //所属基站
	this.cmbbsId = new Ext.form.ComboBox({
		id : 'cmbbsId',
		width : 130,
		listWidth:150,
        fieldLabel : '所属基站',
        store:this.bsIdStore,
        //typeAhead:true,
		valueField : 'nrId',
		displayField :'nrName',
        name : 'bsId',
        mode: 'local',
        emptyText:'',
        triggerAction: 'all',
        selectOnFocus: true	
	});
	//this.bsIdStore.load();
	
	this.cmbDistrictList.on("select",function(){	
			var cmb = Ext.getCmp('cmbDistrictList');	
			var cmbBs = Ext.getCmp('cmbbsId');		
    		cmbBs.clearValue();
    		cmbBs.store.load({params:{'distId':cmb.getValue()}});  		
	});
   
    //经度 
    this.txtAddressInfoLongitude = new Ext.form.TextField({
    	fieldLabel : '经度',
    	name : 'addressInfo.longitude',
		width : 150
    });
    //楼宇纬度
    this.txtAddressInfoLatitude = new Ext.form.TextField({
    	fieldLabel : '纬度',
    	name : 'addressInfo.latitude',
		width : 150
    });
    //图标ID
    this.txtGisIconId = new Ext.form.Hidden({
    	name: 'gis.iconId'
    });
    //绘制直放站
    this.btnDrawGis = new Ext.Button({
        text: '绘制直放站',
        tooltip: {text: '绘制直放站'},
        handler: this.viewGis,
        scope: this
    });
    
    //GIS信息--FormPanel
    this.gisform = new Ext.form.FormPanel({
		bodyStyle : 'padding: 5px 5px 0',
		frame :true,
		height:420,
		width : 700,
		labelAlign: 'right',
		labelWidth : 120,
		layout : 'table',
		layoutConfig : {columns:2},
		items:[
			{layout:'form',items:[this.cmbDistrictList]},
			{layout:'form', items:[this.cmbbsId]},
			{layout:'form', items:[this.txtAddressInfoLongitude]},
            {layout:'form', items:[this.txtAddressInfoLatitude]},
            {colspan:2,layout:'form', items:[this.txtGisIconId]},
            {layout:'form', items:[this.txtGisType]},
            {colspan:2,layout:'form', items:[this.btnDrawGis]},
            {layout:'form', items:[this.txtGisId]}
		]
	});
	
	 this.tabs = new Ext.TabPanel({
        width:700,
        activeTab: 0,
        frame:true,
        height : 420,
        deferredRender:false, 
		layoutOnTabChange:true,
		
        items:[
            {items:this.basicForm, title: '基本信息'},
            {items:this.gisform, title: 'Gis信息'}      
        ]
    });
	
	GridBsRepeater.Detail.superclass.constructor.call(this,{
		title : '直放站信息',
		bodyStyle: 'padding: 5px 5px 0',
        autoHeight: true,
        width: 730,
        resizable: false,
        plain: true,
        modal: true,
        autoScroll: true,
        closeAction: 'hide',
        items :[this.tabs],
        buttons: [{
            text: '保存',
            cls: 'x-btn-text-icon btn-save',
            handler: this.onSave,
            scope: this
        }, {
            text: '关闭',
            cls: 'x-btn-text-icon btn-cancel',
            handler: this.hide.createDelegate(this, [])
        }]
		
	});
	this.connSave = new Ext.data.Connection({
		url: '../gridnetworkresource/save.form?timesnap=' + Date.parse(new Date()),
		method: 'POST'
	});
};

Ext.extend(GridBsRepeater.Detail,Ext.Window,{

	initData : function(id) {
			this.basicForm.getForm().reset();
			this.gisform.getForm().reset();
			this.bsIdStore.load();
			
			
			var connection = new Ext.data.Connection({
						url : '../gridnetworkresource/prepare.form?timesnap=' + Date.parse(new Date()),
						method : 'POST'
					});
			if(id!=null){
				Utils.request(connection, {
						params : {
							nrId : id
						},
						scope : this,
						success : function(resp, action) {
							
							var nr = resp.gridNetworkResource;
							var rpt = resp.gridBsRepeater;
							var gis = resp.gisInfo;
							var add = resp.addressInfo;
							
							//网络资源ID
							this.scope.txtNrId.setValue(nr.nrId);
							//直放站名称
							this.scope.txtNrName.setValue(nr.nrName);
							//光纤位置描述
							this.scope.txtLocationDesc.setValue(nr.locationDesc);
							//资源类型
							this.scope.txtNrType.setValue(nr.nrType);
							//站址
							this.scope.txtNrAddress.setValue(nr.nrAddress);
							//路
							this.scope.txtAddressInfoStreet.setValue(add.street);
							//弄
							this.scope.txtAddressInfoAlley.setValue(add.alley);
							//号
							this.scope.txtAddressInfoDoorNum.setValue(add.doorNum);
							//楼名
							this.scope.txtAddressInfoBuildingName.setValue(add.buildingName);
							//楼层
							this.scope.txtAddressInfoFloor.setValue(add.floor);
							//直放站位置描述
							this.scope.txtLocationDesc.setValue(nr.locationDesc);
							//直放站编号
							this.scope.txtrptId .setValue(rpt.rptId);
							//设备具体位置
							this.scope.txtEquipmentPosition.setValue(rpt.equipmentPosition);
							//覆盖面积（万平方米）
							this.scope.txtareaSize.setValue(rpt.areaSize);
							//直放站类型
							this.scope.cmbRptType.setValue(rpt.rptType);
							//设备型号
							this.scope.txtEquipmentType.setValue(rpt.equipmentType);
							//监控卡号
							this.scope.txtMonitoringCardId.setValue(rpt.monitoringCardId);
							//入网年月
							this.scope.dfEnterNetDate.setValue(Ext.util.Format.date(rpt.enterNetDate,'m/d/y'));
							//区域
							this.scope.txtAreaRange.setValue(rpt.areaRange);
							//设备厂商
							this.scope.txtEquipmentManufacturer.setValue(rpt.equipmentManufacturer);
							
							//片区ID
							this.scope.cmbDistrictList.setValue(nr.distId);
							this.scope.bsIdStore.load({params:{'distId':nr.distId}});
							//所属基站
							this.scope.cmbbsId.setValue(rpt.bsId);
							//GisId
							this.scope.txtGisId.setValue(gis.id);
							//经度
							this.scope.txtAddressInfoLatitude.setValue(add.latitude);
							//纬度
							this.scope.txtAddressInfoLongitude.setValue(add.longitude);
							//IconID
							this.scope.txtGisIconId.setValue(gis.iconId);
									
						},
						after : function() {
							
						}
					});
			}
		},
	
		onSave: function(btn, event) {
			var form =this.basicForm.getForm();
			if (!form.isValid()) {
				return;
			}
			form.doAction('submit', { 
				method : 'post',
				url : '../gridnetworkresource/save.form', 
				params: {
					'distId' : this.cmbDistrictList.getValue(),
					'addressInfo.longitude':this.txtAddressInfoLongitude.getValue(),
					'addressInfo.latitude':this.txtAddressInfoLatitude.getValue(),
					'gisInfo.type':this.txtGisType.getValue(),
					'gisInfo.iconId':this.txtGisIconId.getValue(),
					'bsId' : this.cmbbsId.getValue(),
					'gisInfo.id' : this.txtGisId.getValue()
				},
				scope: this,
				success: function(form, action) {
					this.parentList.update();
					this.hide();
				},
				after: function() {}
			});
	},
		
		initGis:function(name, iconId, coordx, coordy){
			this.txtAddressInfoLongitude.setValue(coordx);
			this.txtAddressInfoLatitude.setValue(coordy);
			this.txtGisIconId.setValue(iconId);
		},
		viewGis:function(){
			var did = this.cmbDistrictList.getValue();
			if(did==''){
				Utils.warn('请先选择片区！');
				return;
			}
			var iconId = this.txtGisIconId.getValue();
			if(iconId==''){
				iconId = 503;
			}
			var str = OMS.GIS_IP+'/gis_for_management.jsp?did=' + this.cmbDistrictList.getValue() + 
			'&name=' + this.txtNrName.getValue() 
			+ '&iconId=' + iconId 
			+ '&type='+ this.txtGisType.getValue()
			+ '&coordx=' +this.txtAddressInfoLongitude.getValue()
			+ '&coordy='+this.txtAddressInfoLatitude.getValue();
			
			window.open(encodeURI(str), '_blank', 'toolbar=no,location=no,directories=no,scrollbars=no,menubar=no,width=1000,height=600,resizable=no,left=0,top=0, status=no');	
		}
});




